<template>
  <div class="clas_All">
    <el-row>
      <el-col :span="24">
        <el-form :model="queryParams" size="small" :inline="true">
          <el-form-item prop="" style="height: 40px">
            <el-select
              v-model="byMonth.relateId"
              placeholder="请选择部门"
              clearable
              @change="deptChange"
            >
              <el-option
                v-for="dict in deptOptions"
                :key="dict.relateId"
                :label="dict.label"
                :value="dict.relateId"
              />
            </el-select>
          </el-form-item>
          <el-form-item prop="" style="height: 40px">
            <el-date-picker
              clearable
              v-model="queryParams.createdTime"
              type="month"
              placeholder="选择月"
              @change="createdTimeChange"
              :disabled="mouday"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item prop="" style="height: 40px">
            <el-select
              v-model="queryParams.pandianCode"
              placeholder="1号至10号"
              clearable
              :disabled="mount"
            >
              <el-option
                v-for="dict in NewDropDownList"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          <el-button type="primary" size="mini" @click="getList"
            >查询
          </el-button>
        </el-form>
      </el-col>
    </el-row>

    <el-row>
      <el-col>
        <el-table :data="tableData">
          <el-table-column align="center" label="序号" type="index" width="50">
          </el-table-column>
          <el-table-column
            label="原料亏损非出品部门"
            prop="deptName"
            align="center"
          ></el-table-column>
          <el-table-column
            label="涉及金额/元"
            prop="amout"
            align="center"
          ></el-table-column>
          <el-table-column
            label="涉及原料/种"
            prop="stapNum"
            align="center"
          ></el-table-column>
          <el-table-column label="描述" align="center">
            <template slot-scope="scope">
              <div>
                <span v-if="scope.row.flag == -1">本期虚减利润</span>
                <span v-if="scope.row.flag == 1">本期虚增利润</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center">
            <template slot-scope="scope">
              <el-button size="mini" type="text" @click="OpenClcik(scope.row)"
                >部门诊断详情</el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { getPanDianCode, FindShopBom } from "@/api/system/stock";
import {
  diagnosisStapProlossAnalys,
  diagnosisStapProlossAnalysDetail,
} from "@/api/system/cost.js";
export default {
  data() {
    return {
      tableData: [],
      queryParams: {},
      deptOptions: [],
      DropDownList: [],
      NewDropDownList: [],
      byMonth: {},
      mouday: true,
      mount: true,
      defaultProps: {
        children: "children",
        label: "label",
      },
    };
  },
  created() {
    // this.getList();
    this.getFind();
  },
  methods: {
    OpenClcik(v) {
      this.$router.push({
        path: "/subclass-department",
        query: {
          ids: v.ids,
        },
      });
    },
    getList() {
      diagnosisStapProlossAnalys(this.queryParams).then((res) => {
        if (res.code == 200) {
          this.tableData = res.data;
          this.$forceUpdate();
        }
      });
    },
    getFind() {
      FindShopBom().then((res) => {
        if (res.code == 200) {
          this.deptOptions = res.data;
        }
      });
    },
    createdTimeChange(v) {
      let data = new Date(v);
      let y = data.getFullYear();
      let m = data.getMonth() + 1;
      this.byMonth.pandianData = y + String(m).padStart(2, "0");
      getPanDianCode(this.byMonth).then((res) => {
        if (res.code == 200) {
          this.DropDownList = res.data;
          this.NewDropDownList = [];
          this.DropDownList.forEach((element) => {
            let label =
              new Date(element.startTime).getDate() +
              "号-" +
              new Date(element.endTime).getDate() +
              "号";
            this.NewDropDownList.push({
              value: element.pandianCode,
              label: label,
            });
          });
          if (res.data != []) {
            this.mount = false;
          }
        }
      });
    },
    deptChange(v) {
      if (v) {
        this.mouday = false;
      } else {
        this.mouday = true;
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.clas_All {
  margin: 20px;
}
</style>
